package se.janlindblom.ordning.desktop.gui;

/**
 * $Id: Main.java 81 2009-12-11 13:38:06Z lindblom.jan $
 * 
 * Copyright (c) 2009, Jan Lindblom
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * * Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 * 
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * 
 * * Neither the name of the project nor the names of its contributors may be
 *   used to endorse or promote products derived from this software without
 *   specific prior written permission.
 *   
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * 
 */

import java.text.DateFormat;
import java.util.Date;
import java.util.Observable;
import java.util.Observer;
import se.janlindblom.ordning.helper.Bucket;
import se.janlindblom.ordning.helper.Puls;
import se.janlindblom.ordning.typ.samling.Kategorier;

/**
 *
 * @author Jan Lindblom (lindblom.jan@gmail.com)
 * @version $Rev: 81 $
 */
public class Main extends javax.swing.JFrame implements Observer {

    /** Creates new form Main */
    public Main() {
        this.setName("Main Window");
        initComponents();
        df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        taskButtonGroup = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        task6Combo = new javax.swing.JComboBox();
        task4Combo = new javax.swing.JComboBox();
        task5Combo = new javax.swing.JComboBox();
        task8Toggle = new javax.swing.JToggleButton();
        task9Toggle = new javax.swing.JToggleButton();
        moreThanSixTasksLabel = new javax.swing.JLabel();
        task7Toggle = new javax.swing.JToggleButton();
        task5Toggle = new javax.swing.JToggleButton();
        task6Toggle = new javax.swing.JToggleButton();
        task8Combo = new javax.swing.JComboBox();
        task7Combo = new javax.swing.JComboBox();
        task9Combo = new javax.swing.JComboBox();
        stopButton = new javax.swing.JButton();
        task2Toggle = new javax.swing.JToggleButton();
        task1Toggle = new javax.swing.JToggleButton();
        task4Toggle = new javax.swing.JToggleButton();
        task1Combo = new javax.swing.JComboBox();
        moreThanThreeTasksLabel = new javax.swing.JLabel();
        threeMajorTasksLabel = new javax.swing.JLabel();
        task3Toggle = new javax.swing.JToggleButton();
        task3Combo = new javax.swing.JComboBox();
        task2Combo = new javax.swing.JComboBox();
        breakToggle = new javax.swing.JToggleButton();
        lunchToggle = new javax.swing.JToggleButton();
        timeLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Ordning");

        task6Combo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        task4Combo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        task5Combo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        taskButtonGroup.add(task8Toggle);
        task8Toggle.setText("08");

        taskButtonGroup.add(task9Toggle);
        task9Toggle.setText("09");

        moreThanSixTasksLabel.setText("More than six tasks?!");

        taskButtonGroup.add(task7Toggle);
        task7Toggle.setText("07");

        taskButtonGroup.add(task5Toggle);
        task5Toggle.setText("05");
        task5Toggle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                task5ToggleActionPerformed(evt);
            }
        });

        taskButtonGroup.add(task6Toggle);
        task6Toggle.setText("06");

        task8Combo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        task7Combo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        task9Combo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        stopButton.setText("Stop!");
        stopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopButtonActionPerformed(evt);
            }
        });

        taskButtonGroup.add(task2Toggle);
        task2Toggle.setText("02");
        task2Toggle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                task2ToggleActionPerformed(evt);
            }
        });

        taskButtonGroup.add(task1Toggle);
        task1Toggle.setText("01");
        task1Toggle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                task1ToggleActionPerformed(evt);
            }
        });

        taskButtonGroup.add(task4Toggle);
        task4Toggle.setText("04");

        task1Combo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        moreThanThreeTasksLabel.setText("More than three tasks?");

        threeMajorTasksLabel.setText("Three major tasks for today.");

        taskButtonGroup.add(task3Toggle);
        task3Toggle.setText("03");
        task3Toggle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                task3ToggleActionPerformed(evt);
            }
        });

        task3Combo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        task2Combo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        taskButtonGroup.add(breakToggle);
        breakToggle.setText("Break!");
        breakToggle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                breakToggleActionPerformed(evt);
            }
        });

        taskButtonGroup.add(lunchToggle);
        lunchToggle.setText("Lunch!");
        lunchToggle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lunchToggleActionPerformed(evt);
            }
        });

        timeLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        timeLabel.setText("jLabel1");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(timeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
                    .addComponent(threeMajorTasksLabel)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(task1Toggle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(task1Combo, 0, 150, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(task2Toggle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(task2Combo, 0, 150, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(task3Toggle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(task3Combo, 0, 150, Short.MAX_VALUE))
                    .addComponent(moreThanThreeTasksLabel)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(task4Toggle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(task4Combo, 0, 150, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(task5Toggle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(task5Combo, 0, 150, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(task6Toggle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(task6Combo, 0, 150, Short.MAX_VALUE))
                    .addComponent(moreThanSixTasksLabel)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(task7Toggle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(task7Combo, 0, 150, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(task8Toggle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(task8Combo, 0, 150, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(task9Toggle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(task9Combo, 0, 150, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(stopButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(breakToggle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lunchToggle)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(threeMajorTasksLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(task1Toggle)
                    .addComponent(task1Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(task2Toggle)
                    .addComponent(task2Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(task3Toggle)
                    .addComponent(task3Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(moreThanThreeTasksLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(task4Toggle)
                    .addComponent(task4Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(task5Toggle)
                    .addComponent(task5Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(task6Toggle)
                    .addComponent(task6Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(moreThanSixTasksLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(task7Toggle)
                    .addComponent(task7Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(task8Toggle)
                    .addComponent(task8Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(task9Toggle)
                    .addComponent(task9Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(stopButton)
                    .addComponent(breakToggle)
                    .addComponent(lunchToggle))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(timeLabel))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(511, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void task1ToggleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_task1ToggleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_task1ToggleActionPerformed

    private void task5ToggleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_task5ToggleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_task5ToggleActionPerformed

    private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed
        taskButtonGroup.clearSelection();
    }//GEN-LAST:event_stopButtonActionPerformed

    private void task2ToggleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_task2ToggleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_task2ToggleActionPerformed

    private void task3ToggleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_task3ToggleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_task3ToggleActionPerformed

    private void breakToggleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_breakToggleActionPerformed
        // "break" is a hidden special category for keeping track of breaks.
    }//GEN-LAST:event_breakToggleActionPerformed

    private void lunchToggleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lunchToggleActionPerformed
        // "lunch" is a special case of "break"
    }//GEN-LAST:event_lunchToggleActionPerformed

    private Kategorier categories;
    private DateFormat df;
    private Bucket bucket;

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton breakToggle;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JToggleButton lunchToggle;
    private javax.swing.JLabel moreThanSixTasksLabel;
    private javax.swing.JLabel moreThanThreeTasksLabel;
    private javax.swing.JButton stopButton;
    private javax.swing.JComboBox task1Combo;
    private javax.swing.JToggleButton task1Toggle;
    private javax.swing.JComboBox task2Combo;
    private javax.swing.JToggleButton task2Toggle;
    private javax.swing.JComboBox task3Combo;
    private javax.swing.JToggleButton task3Toggle;
    private javax.swing.JComboBox task4Combo;
    private javax.swing.JToggleButton task4Toggle;
    private javax.swing.JComboBox task5Combo;
    private javax.swing.JToggleButton task5Toggle;
    private javax.swing.JComboBox task6Combo;
    private javax.swing.JToggleButton task6Toggle;
    private javax.swing.JComboBox task7Combo;
    private javax.swing.JToggleButton task7Toggle;
    private javax.swing.JComboBox task8Combo;
    private javax.swing.JToggleButton task8Toggle;
    private javax.swing.JComboBox task9Combo;
    private javax.swing.JToggleButton task9Toggle;
    private javax.swing.ButtonGroup taskButtonGroup;
    private javax.swing.JLabel threeMajorTasksLabel;
    private javax.swing.JLabel timeLabel;
    // End of variables declaration//GEN-END:variables

    @Override
    public void update(Observable o, Object arg) {
        if (o.getClass().equals(Puls.class)) {
            Long tick = (Long) arg;
            Date d = new Date(tick);
            timeLabel.setText(df.format(d));
        } else if (o.getClass().equals(Bucket.class)) {
            System.err.println("Bucket: " + bucket.peek());
        }else {
            System.err.println("update(" + o.getClass().getName() + ", " + arg.toString() + ")");
        }
    }

    public void setBucket(Bucket bucket) {
        this.bucket = bucket;
    }

    public void setCategories(Kategorier categories) {
        this.categories = categories;
    }
}
